package com.example.feign.controller;

import com.example.feign.service.FeignService;
import io.swagger.annotations.Api;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "feign测试")
@RestController
@Slf4j
public class ConsumerFeignController {

    @Resource
    private FeignService feignService;

    @GetMapping("consumer/feign/test/{message}")
    public String test(@PathVariable String message) {
        long start = System.currentTimeMillis();
        log.info("调用provider开始，{}", start);
        String result = null;
        try {
            result = feignService.getProviderTest(message);
        } catch (Exception e) {
            log.info("调用provider结束，{}ms", System.currentTimeMillis() - start);
            throw new RuntimeException(e);
        }
        return result;
    }

    @GetMapping("consumer/feign/config/{message}")
    public String config(@PathVariable String message) {
        return feignService.getProviderTest(message);
    }

    @GetMapping("consumer/feign/sentinel/test/{message}")
    public String sentinelTest(@PathVariable String message) {
        return feignService.providerSentinelTest(message);
    }


    @GetMapping("/feign/config/{message}")
    public String ft(@PathVariable String message) {
        return message;
    }
}
